package com.bit.librarymanagementsystem.aspect;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class TimeAspect {
    /**
     * 记录方法耗时
     */

    @Around("execution(* com.bit.librarymanagementsystem.Controller.*.*(..))")
    public Object recordTime(ProceedingJoinPoint pjp) throws Throwable {
        //获取当前时间
        long begin=System.currentTimeMillis();
        //执行原始方法
        Object result=pjp.proceed();
        //记录方法结束时间
        long end=System.currentTimeMillis();

        log.info(pjp.getSignature()+"执行耗时:{}ms",end-begin);
        return result;
    }

}
